
/**
** \file       do_group.c
**
** \brief      this function parse the do_group rule
**
** \author     Ben M'rad Hanna, Laterem Hamza, Boillot Ulysse
**             and De Olivera Guillaume
**
** \version    1.0
**
** \date       28 Novembre 2010
**
*/

#include "rules.h"

static s_dogroup        *my_malloc(s_dogroup            *group)
{
  group->todo = calloc(1, sizeof (s_cmpdlist));

  return (group);
}

static s_dogroup        *my_free(s_dogroup              *group)
{
  free(group->todo);
  group->todo = NULL;

  return (NULL);
}

s_dogroup               *rule_do_group(s_dogroup        *group)
{
  if (g_data->lexer == NULL)
    return (NULL);

  if (!strcmp(g_data->lexer->token->id, "do"))
  {
    g_data->lexer = g_data->lexer->next;

    if (g_data->lexer == NULL)
      return (NULL);

    group = my_malloc(group);

    if (rule_compound_list(group->todo) == NULL)
      return (my_free(group));

    if (g_data->lexer != NULL)
    {
      if (strcmp(g_data->lexer->token->id, "done"))
        return (my_free(group));

      g_data->lexer = g_data->lexer->next;

      return (group);
    }
  }
  return (NULL);
}
